home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: C compilers which optimize tail calls (was: GOTO controversy)
- Date: Wed, 10 Apr 96 11:39:30 GMT
- Organization: none
- Message-ID: <829136370snz@genesis.demon.co.uk>
- References: <oun34tm3c7.fsf@lynx.cs.byu.edu> <DpCv8o.9Mw@ida.liu.se> <ouivfcnaxq.fsf@lynx.cs.byu.edu> <4keb44$86h@camelot.ccs.neu.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4keb44$86h@camelot.ccs.neu.edu>
- will@ccs.neu.edu "William D Clinger" writes:
-
- >Stack allocation of mutable variables and data often
- >interferes with proper tail recursion. Consider
- >
- >int f (int n) {
- > int A[10];
- > int i;
- > for (i = 0; i < 10; i = i + 1)
-
- It is more natural to write i = i + 1 as ++i or i++ in C.
-
- > A[i] = n * i;
- > return g (&n, &(A[0]));
- >}
- >
- >Yes, it is possible to write a correct C compiler that
- >compiles the tail-recursive call to g as a tail recursion.
-
- What tail recursion? There's no recursion there at all. With tail recursion
- the function is calling itself before returning so the local variables
- between invocations are somewhat compatible. There was a case of mutual
- recursion posted earlier. This is trickier to deal with but could be reduced
- to simple recursion with appropriate function inlining (although the scope
- of that is realistically limited to fairly simple cases).
-
- >I very much doubt whether any production C compiler
- >can be relied upon to generate properly tail recursive code.
-
- Many do for cases of simple (i.e. involving a single function) tail recursion
- but it still remains that portable C code can't depend on it.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-